package com.springdoor.web.controller.goods;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.springdoor.common.annotation.Log;
import com.springdoor.common.core.controller.BaseController;
import com.springdoor.common.core.domain.AjaxResult;
import com.springdoor.common.enums.BusinessType;
import com.springdoor.goods.domain.SprdGoodsDesc;
import com.springdoor.goods.service.ISprdGoodsDescService;
import com.springdoor.common.utils.poi.ExcelUtil;
import com.springdoor.common.core.page.TableDataInfo;

/**
 * 商品介绍详情Controller
 * 
 * @author llshs
 * @date 2024-08-09
 */
@RestController
@RequestMapping("/goods/desc")
public class SprdGoodsDescController extends BaseController {

    @Autowired
    private ISprdGoodsDescService sprdGoodsDescService;

    /**
     * 获取商品介绍详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:desc:list')")
    @GetMapping(value = "/list/{gNumber}")
    public AjaxResult getInfo(@PathVariable("gNumber") String gNumber) {
        return success(sprdGoodsDescService.selectSprdGoodsDescByGNumber(gNumber));
    }

    /**
     * 获取商品介绍详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:desc:query')")
    @GetMapping(value = "/{descId}")
    public AjaxResult getInfo(@PathVariable("descId") Long descId) {
        return success(sprdGoodsDescService.selectSprdGoodsDescById(descId));
    }

    /**
     * 新增商品介绍详情
     */
    @PreAuthorize("@ss.hasPermi('goods:desc:add')")
    @Log(title = "商品介绍详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SprdGoodsDesc sprdGoodsDesc)
    {
        sprdGoodsDesc.setCreateBy(getUsername());
        sprdGoodsDesc.setUpdateBy(getUsername());
        System.out.println(sprdGoodsDesc);
        return toAjax(sprdGoodsDescService.insertSprdGoodsDesc(sprdGoodsDesc));
    }

    /**
     * 修改商品介绍详情
     */
    @PreAuthorize("@ss.hasPermi('goods:desc:edit')")
    @Log(title = "商品介绍详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SprdGoodsDesc sprdGoodsDesc)
    {
        sprdGoodsDesc.setUpdateBy(getUsername());
        System.out.println(sprdGoodsDesc);
        return toAjax(sprdGoodsDescService.updateSprdGoodsDesc(sprdGoodsDesc));
    }

    /**
     * 删除商品介绍详情
     */
    @PreAuthorize("@ss.hasPermi('goods:desc:remove')")
    @Log(title = "商品介绍详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{descId}")
    public AjaxResult remove(@PathVariable Long descId) {
        return toAjax(sprdGoodsDescService.deleteSprdGoodsDescByDescId(descId));
    }
}
